import React, { Dispatch } from 'react';
import { ProcdefManageAPI } from '../common/type';

interface ProcdefRightTableTypes {
  dataSource: Record<string, any>[];
  loading: boolean;
  getProcdefTableData: (request: ProcdefManageAPI.IGridRequestType) => any;
  mapList: Record<string, any>;
  pagination: Record<string, any>; //分页参数
  otherParams: Record<string, any>; //当前请求参数
  searchList: ProcdefManageAPI.ISearchList;
  reloadTableData: () => void;
  [key: string]: any;
}

/**
 * Context 默认值类型
 */
type ManageContextTypes = {
  rightTableProps: ProcdefRightTableTypes;
  curRes: Record<string, any>;
  prefixCls: string;
  reloadLeftTree: (res: any) => void;

  leftSelectKeys: string[];
  leftExpandedKeys: string[];
  leftAutoExpandParent: boolean;
  procdefDispatch: Dispatch<any>;
  typeSelectRow: Record<string, any>;
  dicFlowSelectRow: Record<string, any>;
};

/**
 * useContext
 * @rightTableProps 公共表格所需参数
 * @curRes 权限
 * @prefixCls 根节点类名
 * @reloadLeftTree 刷新左侧类型
 * @leftSelectKeys 左侧树选中节点Key
 * @leftExpandedKeys 左侧树展开节点Key
 * @leftAutoExpandParent 左侧树是否自动展开
 * @procdefDispatch reduce 派发器
 */
const INIT_PROCDEFMANAGE_CONTEXT: ManageContextTypes = {
  rightTableProps: {
    dataSource: [],
    loading: false,
    getProcdefTableData: ({}) => {},
    mapList: [],
    pagination: {},
    otherParams: {},
    searchList: [],
    reloadTableData: () => {},
  },
  curRes: {},
  prefixCls: 'activiti-manage-',
  reloadLeftTree: (res: any) => {},
  leftSelectKeys: [],
  leftExpandedKeys: [],
  leftAutoExpandParent: false,
  procdefDispatch: () => {},
  typeSelectRow: {},
  dicFlowSelectRow: {},
};

const ProcdefManageContext = React.createContext(INIT_PROCDEFMANAGE_CONTEXT);

export { ProcdefManageContext };
